home *** CD-ROM | disk | FTP | other *** search
- Path: news.db.erau.edu!kochank
- From: kochank@news.db.erau.edu (Konrad Kochan)
- Newsgroups: comp.lang.c++
- Subject: PLEASE Help! :(
- Date: 9 Mar 1996 20:48:46 GMT
- Organization: Embry-Riddle Aeronautical University
- Message-ID: <4hsqre$4d7@deadbird.db.erau.edu>
- NNTP-Posting-Host: 155.31.1.1
- NNTP-Posting-User: kochank
- Keyword:
- X-Newsreader: TIN [version 1.2 PL2]
-
- Howdy.. I have a program to write, but I'm clueless... Now I could
- give you a 100 excuses and blame the instructor (and I should cause
- all of it would be true.. :)
-
- Anyways, I'm clueless.. can someone, a good samaritan (or someone just
- bored..) help me out!
-
- Here is the program statement..
-
- Write a C program to sort, using any sorting method, a text file
- named RECORDS.DAT, of unknown length, of records organized as follows:
-
- Field 1. Contains an integer.
- Field 2. Contains a string of exactly 20 characters.
- Field 3. Contains a float followed by a newline character.
-
- Example of file organization:
-
- 234 Numa Chaikin 33000.0
-
-
- 234 Numa Chaikin 33000.0
- 75 advertisements 55.55
- 901 Shepard 15255.5
- 3 Brook 120050.0
- 888 non-descriptive 0.0
-
- Sorting has to be done lexicographically, that is, by the second field
- using alphabetical order. This means that:
-
- 1. Upper-case and lower-case letters should be treated identically.
- For example, the right order for a part of the list above is:
- 888 non-descriptive 0.0
- 234 Numa Chaikin 33000.0
-
- 2. The only punctuation sign used in strings is a dash '-', which
- should be ignored in sorting (but not removed from words).
-
-
- ~
- ~
- ~
- ~
-
- And here is what I got so far.. which DOESN'T work (right or otherwise, I
- can't even get the program to scan the right fields from the file.. :(
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- /* Global Variable Definition */
-
- int IntArr[512][5];
- char WordsArr1[512][10];
- char WordsArr2[512][10];
- float FloatArr[512][5];
- char inbuff[80];
- int index=0;
-
- /* Function declaration */
-
- void Welcome(void);
- void Goodbye(void);
-
- main()
- {
-
- main()
- {
- /* Next function opens a file, if the file is missing, it prints
- an error message */
-
- int i;
- FILE * fin, * fout;
- if (!(fin = fopen("RECORDS.DAT", "r")))
- {
- printf("Something is wrong: Probably file missing.\n");
- exit(1); /* Program exits here if file is missing. */
- }
- printf("\nInput File = RECORDS.DAT\n");
- /* This function prints a Welcome message */
-
- /* Welcome(); */
-
- /* This function scans in the array */
-
- while (fgets(inbuff,80,fin) !=NULL)
- {
- sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[inde
- x],&FloatArr[index]);
-
- {
- sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[inde
- x],&FloatArr[index]);
- index++;
- }
-
- /* Opens the output file */
-
- if (!(fout = fopen("test", "w")))
- {
- printf("Something is wrong: File might be write protected.\n");
- exit(1); /* Program exits here if file can't be opened. */
- }
-
- for (i=0; i<index; i++)
- fprintf(fout, "%d %s %s %4.2f\n", IntArr[i], WordsArr1[i],WordsArr2[i],
-
- FloatArr[i]);
-
- /* Prints the sorted array to the screen */
-
- for (i=0; i<index; i++)
- printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
-
- for (i=0; i<index; i++)
- printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
- WordsArr2[i],FloatArr[i]);
- fclose(fin);
- fclose(fout);
- }
-
-
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
-
- If you can either give me hints, rewrite the above, or write a totaly
- new program I would appreciate it.. I know its a lot to ask for (to do some-
- one elses homework pretty much..) but I'm really clueless..
-
- Thank you in advance!
-